VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmMenu 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Seguridad Menu"
   ClientHeight    =   5310
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5820
   Icon            =   "frmMenu.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5310
   ScaleWidth      =   5820
   Begin MSComctlLib.TreeView Arbol 
      Height          =   3735
      Left            =   120
      TabIndex        =   2
      Top             =   1440
      Width           =   5535
      _ExtentX        =   9763
      _ExtentY        =   6588
      _Version        =   393217
      Style           =   7
      Checkboxes      =   -1  'True
      Appearance      =   1
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Height          =   975
      Left            =   120
      TabIndex        =   4
      Top             =   360
      Width           =   5535
      Begin VB.CommandButton cmdVer 
         Appearance      =   0  'Flat
         BackColor       =   &H00FFFFFF&
         Caption         =   "Ver"
         Height          =   315
         Left            =   4080
         MaskColor       =   &H00FFFFFF&
         Style           =   1  'Graphical
         TabIndex        =   1
         Top             =   480
         Width           =   855
      End
      Begin VB.ComboBox cmbGrupUsu 
         Appearance      =   0  'Flat
         Height          =   315
         Left            =   120
         Style           =   2  'Dropdown List
         TabIndex        =   0
         Top             =   480
         Width           =   3375
      End
      Begin VB.Label Label2 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Grupo de Usuarios:"
         Height          =   375
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   1695
      End
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   2280
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   11
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":08CA
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":0E64
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":13FE
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":1998
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":1F32
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":24CC
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":2A66
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":3000
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":359A
            Key             =   ""
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":3B34
            Key             =   ""
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMenu.frx":40CE
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Toolbar1 
      Align           =   1  'Align Top
      Height          =   360
      Left            =   0
      TabIndex        =   3
      Top             =   0
      Width           =   5820
      _ExtentX        =   10266
      _ExtentY        =   635
      ButtonWidth     =   609
      ButtonHeight    =   582
      Appearance      =   1
      Style           =   1
      ImageList       =   "ImageList1"
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   6
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Key             =   "Aceptar"
            Object.ToolTipText     =   "Aceptar (F5)"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Enabled         =   0   'False
            Key             =   "Cancelar"
            Object.ToolTipText     =   "Cancelar (F8)"
            ImageIndex      =   6
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "Salir"
            Object.ToolTipText     =   "Salir (Esc)"
            ImageIndex      =   11
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Style           =   3
         EndProperty
      EndProperty
      BorderStyle     =   1
   End
End
Attribute VB_Name = "frmMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim con As New ConBaseDatos, nodoID(100) As Integer

Private Sub cmbGrupUsu_GotFocus()

cmbGrupUsu.BackColor = &HFFFFC0

End Sub

Private Sub cmbGrupUsu_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
    Case 13
        SendKeys "{TAB}"
        KeyAscii = 0

    Case 8, 32
        cmbGrupUsu.ListIndex = -1

End Select

End Sub

Private Sub cmbGrupUsu_LostFocus()

cmbGrupUsu.BackColor = &H80000005

End Sub

Private Sub cmdVer_Click()

If cmbGrupUsu.ListIndex = -1 Then
    MsgBox "Seleccione grupo de usuarios", vbCritical, "Error"
    cmbGrupUsu.SetFocus
    Exit Sub
End If

cmbGrupUsu.Enabled = False
cmdVer.Enabled = False
Toolbar1.Buttons.Item(2).Enabled = True
Toolbar1.Buttons.Item(3).Enabled = True
Toolbar1.Buttons.Item(5).Enabled = False
CargarMenu

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 27 'Escape "Salir"
        If Toolbar1.Buttons(5).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(5)
        
    Case 112 'F1 "Ayuta"
        frmPrincipal.manual_Click
        
    Case 116 'F5 "Aceptar"
        If Toolbar1.Buttons(2).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(2)
    
    Case 119 'F8 "Cancelar"
        If Toolbar1.Buttons(3).Enabled Then Toolbar1_ButtonClick Toolbar1.Buttons(3)
        
End Select

End Sub

Private Sub Form_Load()

Abrir Me

con.AbrirRegistros "select * from grupos_usuarios order by nombre", Consulta
Do While Not con.Registros.EOF
    cmbGrupUsu.AddItem DesEditar(con.Registros("nombre"))
    cmbGrupUsu.ItemData(cmbGrupUsu.NewIndex) = CInt(con.Registros("grupo_usuario"))
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros

End Sub

Private Sub Form_Unload(Cancel As Integer)

If Not Toolbar1.Buttons(5).Enabled Then Cancel = True

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

Select Case Button.Key
         
    Case "Salir"
        Unload Me
    
    Case "Aceptar"
        GrabarMenu
        Habilitar
        
    Case "Cancelar"
        Habilitar
       
End Select

End Sub

Private Sub Habilitar()

cmbGrupUsu.Enabled = True
cmdVer.Enabled = True
Toolbar1.Buttons.Item(2).Enabled = False
Toolbar1.Buttons.Item(3).Enabled = False
Toolbar1.Buttons.Item(5).Enabled = True
cmbGrupUsu.ListIndex = -1
Arbol.Nodes.Clear

End Sub

Private Sub CargarNodoID()

Dim i As Integer

Erase nodoID

i = 1
con.AbrirRegistros "select * from menu_grupos_usuarios where grupo_usuario='" & ReplicarCaracter("0", LargoID, cmbGrupUsu.ItemData(cmbGrupUsu.ListIndex)) & "' order by nodoid", Consulta
Do While Not con.Registros.EOF
    nodoID(i) = con.Registros("nodoid")
    i = i + 1
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros

End Sub

Private Function BuscarNodoID(Nodo As Integer) As Boolean

Dim i As Integer

BuscarNodoID = False

For i = 0 To UBound(nodoID)
    If nodoID(i) = Nodo Then
        BuscarNodoID = True
        Exit For
    End If
Next i

End Function

Private Sub CargarMenu()

CargarNodoID

Arbol.Nodes.Add , , , "Menu"
Arbol.Nodes(1).Expanded = True

con.AbrirRegistros "select * from menu where modulo" & Modulo & " order by orden", Consulta
Do While Not con.Registros.EOF
    If con.Registros("parent") = 0 Then
        Arbol.Nodes.Add 1, tvwChild, "N" & con.Registros("nodoid"), con.Registros("caption")
    Else
        Arbol.Nodes.Add "N" & con.Registros("parent"), tvwChild, "N" & con.Registros("nodoid"), con.Registros("caption")
    End If
    Arbol.Nodes.Item(Arbol.Nodes.Count).Checked = BuscarNodoID(con.Registros("nodoid"))
    con.Registros.MoveNext
    DoEvents
Loop
con.CerrarRegistros

End Sub

Private Sub GrabarMenu()

Dim i As Integer

con.BorrarRegistros "menu_grupos_usuarios", "grupo_usuario='" & ReplicarCaracter("0", LargoID, cmbGrupUsu.ItemData(cmbGrupUsu.ListIndex)) & "'"

With Arbol.Nodes
    For i = 1 To .Count
        If .Item(i).Checked Then con.InsertarRegistros "menu_grupos_usuarios", "nodoid,grupo_usuario", Mid(Arbol.Nodes(i).Key, 2) & ",'" & ReplicarCaracter("0", LargoID, cmbGrupUsu.ItemData(cmbGrupUsu.ListIndex)) & "'"
        DoEvents
    Next i
End With

End Sub
